﻿#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

// 692. 前K个高频单词
// 将数据放到vector中⽤⼀个稳定的排序stable_sort
// sort底层时快排，不稳定 
class Solution
{
public:
    // 仿函数
    struct Compare
    {
        bool operator()(const pair<string, int>& x, const pair<string, int>& y)
        {
            return x.second > y.second;
        }
    };
    vector<string> topKFrequent(vector<string>& words, int k)
    {
        map<string, int> countMap;
        for (auto& e : words)
        {
            countMap[e]++;
        }

        vector<pair<string, int>> v(countMap.begin(), countMap.end());

        // 仿函数控制降序
        stable_sort(v.begin(), v.end(), Compare());

        // 取前k个
        vector<string> res;
        for (int i = 0; i < k; i++)
        {
            res.push_back(v[i].first);
        }
        return res;
    }
};


// 单词识别
using namespace std;
bool Compare(const pair<string, int> w1, const pair<string, int> w2)
{
    return w1.second > w2.second;
}
int main()
{
    map<string, int> mp;
    string s;
    while (getline(cin, s))  // 截取单词，用map记录单词
    {
        for (int i = 0, j = 0; i < s.size(); i++)
        {
            if (s[i] == ' ' || s[i] == '.')
            {
                string tmp = s.substr(j, i - j);
                if (isupper(tmp[0]))
                {
                    tmp = tolower(tmp[0]);  // 大写转小写
                }
                j = i + 1;
                mp[tmp]++;
            }
        }
        vector<pair<string, int>> v(mp.begin(), mp.end());
        sort(v.begin(), v.end(), Compare);  
        for (int i = 0; i < v.size(); i++)
        {
            cout << v[i].first << ":" << v[i].second << endl;
        }
    }
    return 0;
}
